<template>
  <div class="search-container">
    <van-cell title="搜索历史">
      <template v-if="isDeleteShow">
        <span @click="searchHistory.splice(0)">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow=false">完成</span>
      </template>
      <van-icon v-else name="delete" @click="isDeleteShow=true" />
    </van-cell>
    <van-cell :title="item" v-for="(item,ind) in searchHistory" :key="item" @click="deleteClick(item,ind)">
      <van-icon name="close" v-show="isDeleteShow" />
    </van-cell>
    <!-- 通用错误 -->
    <van-empty v-if="!searchHistory.length" image="error" description="暂无搜索历史" />
  </div>
</template>

<script>
export default {
  props: {
    searchHistory: {
      type: Array,
      require: true
    }
  },
  name: 'SearchHistory',
  data () {
    return {
      // 控制显示隐藏
      isDeleteShow: false
    }
  },
  methods: {
    // 删除单个
    deleteClick (item, id) {
      // 判断是否在删除状态
      if (this.isDeleteShow) {
        this.$emit('deleteId', id)
      } else {
        // 直接搜索
        this.$emit('searchHistory', item)
      }
    }
  },
  computed: {
  },
  watch: {},
  filters: {},
  components: {},
  created () { },
  mounted () { }
}
</script>

<style lang='less' scoped>
</style>
